<template>
  <div class="result-statistics">
    <div class="title-span">
      <div class="left-box">
        <span class="title-font">模型综合评定</span>
        <div class="select-box">
          流域：
          <el-select v-model="form.zoneId" placeholder="请选择" filterable @change="handleGetList">
            <el-option
              :key="index + item"
              v-for="(item, index) in zoneList"
              :value="item.id"
              :label="item.name"
            />
          </el-select>
        </div>
        <div class="select-box">
          模型类型：
          <!-- <el-cascader
            v-model="form.modelType"
            :options="modelTypeOptions"
            :props="{ value: 'typeId', label: 'typeName', children: 'types' }"
            @change="handleChangeType"
            clearable
          /> -->
          <el-select
            v-model="form.modelType"
            class="m-2"
            placeholder="请选择"
            @change="handleGetList"
          >
            <el-option
              v-for="item in modelTypeOptions"
              :key="item.modelType"
              :label="item.typeName"
              :value="Number(item.modelType)"
            />
          </el-select>
        </div>
      </div>
      <!-- <el-button type="info" class="btn-plus" link>
        <el-icon>
          <FullScreen />
        </el-icon>
      </el-button> -->
    </div>

    <el-table border :data="assessList" class="table-box" :span-method="objectSpanMethod">
      <el-table-column
        prop="modelTypeNm"
        label="模型"
        align="center"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        prop="blknm"
        label="预报断面"
        align="center"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        prop="fcProj"
        label="预报项目"
        align="center"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column label="模型精度" align="center">
        <el-table-column prop="ccNum" label="总场次" align="center"></el-table-column>
        <el-table-column prop="qualNum" label="合格场次" align="center"></el-table-column>
        <el-table-column prop="rate" label="合格率(%)" align="center"></el-table-column>
        <el-table-column prop="grade" label="等级" align="center"></el-table-column>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { reactive, ref } from 'vue'
import { getZone } from '@/services/modules/model-config'
import { getCalcModelQual } from '@/services/modules/model-exam'
import { getCalcModelType } from '@/services/modules/compute-methods'
const zoneList = ref([])
// 列表数据
const assessList = ref([])
const form = reactive({
  zoneId: '',
  modelType: ''
})
// 模型类型列表
const modelTypeOptions = ref([])
// 获取综合评定列表
const handleGetList = async () => {
  const res = await getCalcModelQual(form)
  if (res.code === 200) {
    assessList.value = res.data
  }
}
const getRowSpans = () => {
  const rowSpans = []
  let pos = 0
  for (let i = 0; i < assessList.value.length; i++) {
    if (i === 0) {
      rowSpans.push(1)
      pos = 0
    } else {
      if (assessList.value[i].modelTypeNm === assessList.value[i - 1].modelTypeNm) {
        rowSpans[pos]++
        rowSpans.push(0)
      } else {
        rowSpans.push(1)
        pos = i
      }
    }
  }
  return rowSpans
}
const objectSpanMethod = ({ row, column, rowIndex, columnIndex }) => {
  if (columnIndex === 0) {
    const rowSpans = getRowSpans()
    return {
      rowspan: rowSpans[rowIndex],
      colspan: 1
    }
  }
  if (columnIndex === 1) {
    if (rowIndex % 5 === 0) {
      return {
        rowspan: 5,
        colspan: 1
      }
    } else {
      return {
        rowspan: 0,
        colspan: 0
      }
    }
  }
}
// 获取流域列表
const handleGetZoneList = async () => {
  const res = await getZone()
  if (res.code === 200) {
    zoneList.value = res.data
    form.zoneId = res.data[0].id
  }
}

// 获取模型类型列表
const handleGetModelTypeList = async () => {
  const res = await getCalcModelType()
  if (res.code === 200) {
    modelTypeOptions.value = res.data
    form.modelType = modelTypeOptions.value[0].modelType
  }
}
const initData = async () => {
  await handleGetModelTypeList()
  await handleGetZoneList()
  await handleGetList()
}
initData()
</script>

<style lang="less" scoped>
.result-statistics {
  height: 100%;
  .title-span {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 10px 0 20px;
    height: 50px;
    .left-box {
      display: flex;
      align-items: center;
      width: calc(100% - 100px);
    }
    .btn-plus {
      font-size: 25px;
      font-weight: bold;
    }
    .title-font {
      font-size: 16px;
      font-weight: 600;
    }
    .title-link {
      font-weight: 600;
      font-size: 14px;
      margin-left: 40px;
      color: #409eff;
      cursor: pointer;
    }
    .select-box {
      margin: 0 60px 0 60px;
    }
  }
  .el-table {
    height: calc(100% - 50px);
    border-radius: 0 0 5px 5px;
  }
}
</style>
